﻿// <copyright file="RangeAreaItemsDialog.xaml.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2008-05-27</date>
// <summary>OpenWPFChart library. Dialog to view/edit RangeArea Items.</summary>
// <revision>$Id$</revision>

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel; // For PropertyChangedEventArgs
using System.Windows;
using System.Windows.Input;
using OpenWPFChart.Parts;

namespace OpenWPFChart.Helpers
{
	/// <summary>
	/// Dialog to view/edit RangeArea Items.
	/// Interaction logic for ItemPropertiesDialog.xaml
	/// </summary>
	public partial class RangeAreaItemsDialog : Window
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="RangeAreaItemsDialog"/> class.
		/// </summary>
		/// <param name="dataViewList">List of DataView objects.</param>
		public RangeAreaItemsDialog(IList<DataView> dataViewList)
		{
			InitializeComponent();
			RangeAreaItemsDialogViewModel viewModel = new RangeAreaItemsDialogViewModel(dataViewList);
			viewModel.PropertyChanged += propertyChanged;
			DataContext = viewModel;
		}

		public ObservableCollection<DataView> DataViewCollection
		{
			get { return (DataContext as RangeAreaItemsDialogViewModel).DataViewCollection; }
		}

		/// <summary>
		/// Enable OK button.
		/// Handles the PropertyChanged event of the RangeAreaItemsDialogViewModel object.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
		void propertyChanged(object sender, PropertyChangedEventArgs e)
		{
			btnOK.IsEnabled = true;
		}

		/// <summary>
		/// ListBoxes selection changed.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
		/// <remarks>
		/// Must requery commands when selection is changed.
		/// </remarks>
		private void lbxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
		{
			CommandManager.InvalidateRequerySuggested();
		}

		/// <summary>
		/// Handles the Click event of the btnOK control.
		/// Applyes changes and closes.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}
	}
}
